function openIframe(url,title,w,h){
    layer.open({
        content: url,
        title:[title],
        maxmin:true,
        type:2,
        area:[w,h],
    });
}

$(document).on('click','#add',function(){
    let url = $(this).attr('data-url');
    let title = $(this).attr('data-title');
    let w = $(this).attr('data-w');
    let h = $(this).attr('data-h');
    openIframe(url,title,w,h);
});


$(document).on('click','.edit',function(){
    let url = $(this).attr('data-url');
    let title = $(this).attr('data-title');
    let w = $(this).attr('data-w');
    let h = $(this).attr('data-h');
    openIframe(url,title,w,h);
});

$(document).on('click','.copy',function(){
    let url = $(this).attr('data-url');
    let title = $(this).attr('data-title');
    let w = $(this).attr('data-w');
    let h = $(this).attr('data-h');
    openIframe(url,title,w,h);
});


$(document).on('click','.switch',function(){
    let url = $(this).attr('data-url'),
        status = $(this).attr('data-status'),
        id = $(this).attr('data-id');

    $.post(url,{status:status,id:id},function(res){
          if(res.code == 1){
            layer.msg(res.msg,{icon:1});
            parent.$.pjax.reload('#main',{fragment: '#main'});
            return false;
          }
          layer.msg(res.msg,{icon:2});
    });

});


$(document).on('click','.del',function(){
    let that = $(this);
    let url = that.attr('data-url');
    layer.confirm('您确定要删除吗？', {
        title:['温馨提示'],  
        btn: ['确定','取消'] 
    }, function(){
          $.get(url,function(res){
              if(res.code == 1){
                      layer.msg(res.msg,{icon:1});
                      that.parents('tr').remove();
                      return false;
                    }
                layer.msg(res.msg,{icon:2});
          });
      });
  });

  $(document).on('click','.confrim',function(){
    let that = $(this);
    let url = that.attr('data-url');
    let title = $(this).attr('data-title');
    layer.confirm(title, {
        title:['温馨提示'],  
        btn: ['确定','取消'] 
    }, function(){
          $.get(url,function(res){
              if(res.code == 1){
                      layer.msg(res.msg,{icon:1});
                      that.parents('tr').remove();
                      return false;
                    }
                layer.msg(res.msg,{icon:2});
          });
      });
  });

